package com.db.gffxo.epi.repository;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import com.db.gffxo.epi.domain.EventPublish;


public class EventPublishDaoGen extends SimpleJdbcDaoSupport implements EventPublishDao {

private final static String QUERY = "SELECT * FROM EventPublish";
private final static String REMOVEBYEventType = "DELETE FROM EventPublish WHERE EventType = ?";
private final static String QUERYBYEventType = "SELECT * FROM EventPublish WHERE EventType = ?";
private final static String INSERT = "INSERT INTO EventPublish(EventType, FormatterId, PublisherName, PublisherParams ) VALUES (?,?,?,?)";


	public void removeByEventType(String EventType) {
		getSimpleJdbcTemplate().update(REMOVEBYEventType, EventType);
	}


	public void insert(EventPublish eventPublish) {
		getSimpleJdbcTemplate().update(INSERT
			,eventPublish.getEventType()
			,eventPublish.getPublisherName()
			,eventPublish.getPublisherParams()
		);
	}

	public List getEventPublish() {
		List eventPublishs = getSimpleJdbcTemplate().query(QUERY,
			new ParameterizedRowMapper() {
				public EventPublish mapRow(ResultSet rs, int rowNum) throws SQLException {
				EventPublish eventPublish = new EventPublish();
				eventPublish.setEventType(rs.getString(1));
				eventPublish.setFormatterId(rs.getString(2));
				eventPublish.setPublisherName(rs.getString(3));
				eventPublish.setPublisherParams(rs.getString(4));
				return eventPublish;
			}
		});
		return eventPublishs;
	}
	public List getEventPublishbyEventType(String EventType) {
		List eventPublishs = getSimpleJdbcTemplate().query(QUERYBYEventType,
			new ParameterizedRowMapper() {
				public EventPublish mapRow(ResultSet rs, int rowNum) throws SQLException {
				EventPublish eventPublish = new EventPublish();
				eventPublish.setEventType(rs.getString(1));
				eventPublish.setFormatterId(rs.getString(2));
				eventPublish.setPublisherName(rs.getString(3));
				eventPublish.setPublisherParams(rs.getString(4));
				return eventPublish;
			}
		}
		,EventType);
		return eventPublishs;
	}
}